﻿namespace OleDbDAL.Sales
{
    using DBUtility;
    using IDal.Sales;
    using Model.Sales;
    using System;
    using System.Data;
    using System.Text;

    public class OrdersPayMentListApp : IOrdersPayMentList
    {
        private string dbname = "Systems";

        public void Add(OrdersPayMentListEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into T_OrdersPayMentList(");
            builder.Append("PaymentId,OrdersId,PayMentMoney");
            builder.Append(")");
            builder.Append(" values (");
            builder.Append("" + model.PaymentId + ",");
            builder.Append("" + model.OrdersId + ",");
            builder.Append("" + model.PayMentMoney + "");
            builder.Append(")");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Delete(int PaymentListId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from T_OrdersPayMentList ");
            builder.Append(" where PaymentListId=" + PaymentListId);
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public DataTable GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_OrdersPayMentList ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by PaymentListId ");
            return DbHelperOledb.Query(this.dbname, builder.ToString());
        }

        public int GetMaxId(string swhere)
        {
            return DbHelperOledb.GetMaxID(this.dbname, "PaymentListId", "T_OrdersPayMentList", swhere);
        }

        public OrdersPayMentListEnt GetModel(int PaymentListId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select PaymentListId,PaymentId,OrdersId,PayMentMoney from T_OrdersPayMentList ");
            builder.Append(" where PaymentListId=" + PaymentListId);
            OrdersPayMentListEnt ent = new OrdersPayMentListEnt();
            DataTable table = DbHelperOledb.Query(this.dbname, builder.ToString());
            ent.PaymentListId = PaymentListId;
            if (table.Rows.Count > 0)
            {
                if (table.Rows[0]["PaymentId"].ToString() != "")
                {
                    ent.PaymentId = int.Parse(table.Rows[0]["PaymentId"].ToString());
                }
                if (table.Rows[0]["OrdersId"].ToString() != "")
                {
                    ent.OrdersId = int.Parse(table.Rows[0]["OrdersId"].ToString());
                }
                if (table.Rows[0]["PayMentMoney"].ToString() != "")
                {
                    ent.PayMentMoney = decimal.Parse(table.Rows[0]["PayMentMoney"].ToString());
                }
                return ent;
            }
            return null;
        }

        public DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            string orderString = "";
            int pageCount = 0;
            int recordCount = 0;
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_OrdersPayMentList ");
            return DbHelperOledb.ExecutePager(this.dbname, PageIndex, PageSize, "", builder.ToString(), strWhere, orderString, out pageCount, out recordCount, "PaymentListId");
        }

        public void Update(OrdersPayMentListEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_OrdersPayMentList set ");
            builder.Append("PaymentId=" + model.PaymentId + ",");
            builder.Append("OrdersId=" + model.OrdersId + ",");
            builder.Append("PayMentMoney=" + model.PayMentMoney + "");
            builder.Append(" where PaymentListId=" + model.PaymentListId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }
    }
}

